import java.io.*;
import java.util.*;


/******************************************************************
 * public class SymbolFileLoader
 * public static void mail (String args[])
 * public Hashtable getTickHashTable ()
 * private void loaderTickFile ()
 *
 ******************************************************************/

public class SymbolFileLoader  {

    private static Hashtable tickHashTable = new Hashtable();
    private static Hashtable hsTable = new Hashtable();
    private static Vector tickVector = new Vector();

    private String fileName;

    public static void main( String args[] )
    {
	SymbolFileLoader loader = new SymbolFileLoader();
	loader.setFileName("./Data/testTick.txt");
	loader.loaderTickFile();
	//loader.printTickHashTable (tickHashTable);
	loader.printTickVector(loader.getTickVector());
    }

    public void setFileName(String file_name) {
	fileName = file_name;
    }

    public void loaderTickFile () {
	String symbol = "";
	File name = new File(fileName);

	if ( !name.exists() ) {
	    System.out.println("File:"+name.getName()+" not found!");
	    return;
	}

	if ( name.isFile() ) {
	    System.out.println("Loading file: " + name.getName()+"......");
	    try {
		FileReader r =  new FileReader( name);
		BufferedReader br = new BufferedReader (r);
		String text;

		while( ( text = br.readLine() ) != null ) {
		    if (!text.startsWith("<")) {
			StringTokenizer tokens = new StringTokenizer(text);
			while (tokens.hasMoreTokens()) {
			    symbol = (String)tokens.nextToken();
			    //System.out.println("While loading:"+symbol);
			    tickHashTable.put(symbol, symbol);
			    tickVector.addElement(symbol);
			}
		    }
		}

	       // tickTable.printHashTable(tickTable.getStringHashTable());
	   }
	   catch( IOException e ) {

	   }
       }
    }

    public void loadUrlProfile () {

       File name = new File(fileName);

       if ( !name.exists() ) {
	   System.out.println("File:"+name.getName()+" not found!");
	   return;
       }

       System.out.println("File:"+name.getName()+" found!");

       if ( name.isFile() ) {
	   try {
               RandomAccessFile r =  new RandomAccessFile( name, "r" );
               String text;
	       String key = "";
	       String valume = "";

               while( ( text = r.readLine() ) != null ) {
		   StringTokenizer tokens = new StringTokenizer(text);
		   while (tokens.hasMoreTokens()) {
		       key = tokens.nextToken();
		       valume = tokens.nextToken();

		       if (key != null && valume != null) {
			   hsTable.put(key, valume);
		       }
		   }
	       }


	       //tickTable.printHashTable(tickTable.getStringHashTable());
	   }
	   catch( IOException e ) {

	   }
       }
    }

    public Hashtable getTickHashTable () {
	return tickHashTable;
    }

    public Hashtable getHashTable () {
	return hsTable;
    }

    public Vector getTickVector () {
	return tickVector;
    }

    public void printTickHashTable ( Hashtable hashTab) {
	String symbol = null;

	Enumeration enum = hashTab.keys();  	   
	while (enum.hasMoreElements()) {
	    symbol = (String)enum.nextElement();
	    System.out.println(symbol);
	}
    }

    public void printTickVector ( Vector v) {
	String symbol = null;
	Enumeration enum = v.elements();  	   
	while (enum.hasMoreElements()) {
	    symbol = (String)enum.nextElement();
	    System.out.println(symbol);
	}
    }
}





